﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RoadTeam.Model.BS;
using RoadTeam.Model;
using RoadTeam.Enums;
using RoadTeam.SysInterface;

namespace RoadTeam.BsSystem.CS
{
    public class CsSort_Sys : ICsSort
    {
        public DataTable GetSortIdentifierNull(String SortType)
        {
            SqlWhere where = new SqlWhere();
            where.StrSqlWhere = @"  App_Identifier IS NULL  ";
            where.SelectColumn = @" ID,SortCode,SortName,App_Identifier ";
            return TbCsSort.Select(where, GlobalConfig.RtConnectionString);
        }

        public DataTable GetSortIdentifierNotNull(String SortType)
        {
            SqlWhere where = new SqlWhere();
            where.StrSqlWhere = @"  App_Identifier IS NOT NULL  ";
            where.SelectColumn = @" ID,SortCode,SortName,App_Identifier ";
            return TbCsSort.Select(where, GlobalConfig.RtConnectionString);
        }


        public DataTable GetSortBySortIDs(String SortType, String SortIDs)
        {
            SortIDs = String.IsNullOrEmpty(SortIDs) ? "-1" : SortIDs;
            SqlWhere where = new SqlWhere();
            where.StrSqlWhere = @" ID IN (" + SortIDs + ") And SortType='" + SortType + "'";
            where.SelectColumn = @" ID,SortCode,SortName,App_Identifier ";
            return TbCsSort.Select(where, GlobalConfig.RtConnectionString);
        }


        public bool UpdateSort(DataTable dt)
        {
            return TbCsSort.Update(dt, GlobalConfig.RtConnectionString);
        }


        public static  String GetSortNameByID(String SortID)
        {
            SqlWhere where = new SqlWhere();
            where.Info = new TbCsSort() { ID = Convert.ToDecimal(SortID) };
            where.SelectColumn = @" Top 1 SortName";
            DataTable dt = TbCsSort.Select(where, GlobalConfig.RtConnectionString);

            if (dt.Rows.Count == 0) return String.Empty;
            return dt.Rows[0]["SortName"].ToString();

        }




    }
}
